package cn.hxzy.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result {
    private Integer code;//状态码
    private String msg;//提示信息
    private Integer count;//数据条数
    private Map<String, Object> data = new HashMap<String, Object>();
    private Object data1;
    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(){}; //封装无参构造方法；

    //成功的静态方法
    public static Result ok(){
        Result result=new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setMsg("成功");
        return result;
    }
    //失败的静态方法
    public static Result error(){
        Result result=new Result();
        result.setCode(ResultCode.ERROR);
        result.setMsg("失败");
        return result;
    }
    //重写定义返回的信息（链式编程）
    public Result message(String message){
        this.setMsg(message);
        return this;
    }

    public Result code(Integer code){
        this.setCode(code);
        return this;
    }

    //设置返回的数据条数
    public Result count(int count){
        this.setCount(count);
        return this;
    }
    //封装返回的数据内容
    public Result data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
    public Result data(String key, Object value){
        this.data.put(key, value);
        return this;
    }
    public Result data1(Object value){
        this.setData1(value);
        return this;
    }
}
